/** @file    SystemHost.cpp
 *  @author  Alessandro Polo
 *  @version $Id: SystemHost.cpp 2738 2010-07-07 12:34:17Z alex $
 *  @brief
 * File containing methods for the SystemHost class.
 * The header for this class can be found in SystemHost.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

 #include "SystemHost.h"

 #include <core/ObjectAllocator.h>
 #include <core/DataModels.h>


using namespace std;
namespace wosh {

 WOSH_REGISTER(wosh::SystemHost, "wosh::Object", 1.01, _static_SystemHost)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

SystemHost& SystemHost::operator=(const SystemHost& m) {
	if (this == &m) return *this; // same object?
	this->id = m.id;
	this->hostname = m.hostname;
	this->ip = m.ip;
	this->mac = m.mac;

	return *this;
 }

bool SystemHost::operator==(const SystemHost &other) const {
	if ( this->hostname != other.hostname ) return false;
	if ( this->ip != other.ip ) return false;
	if ( this->mac != other.mac ) return false;
	return true;
 }

void SystemHost::clear() {
	this->id = Utilities::randomLong();
	this->id = _GET_Abs(this->id);
	Object::setName("SystemHost", this->id );
	this->hostname = "";
	this->ip = "";
	this->mac = "";
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

DataFieldCollector<SystemHost>* SystemHost::getDataFields() {
	DataFieldCollector<SystemHost>* fields = new DataFieldCollector<SystemHost>();
	fields->add<long,Variant>(&SystemHost::getID, "ID", 0);
	fields->add<const std::string&, Variant>(&SystemHost::getHostName, "HostName", 1);
	fields->add<const std::string&, Variant>(&SystemHost::getIP, "IP", 2);
	fields->add<const std::string&, Variant>(&SystemHost::getMAC, "MAC", 3);
	fields->add<const URI&,URI>(&SystemHost::getURI, "URI", 4);
	return fields;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool SystemHost::updateHash( DataHashContext* hash_context ) const {
	if ( hash_context == NULL ) return false;
	bool ret = Object::updateHash(hash_context);
	ret = hash_context->update( this->id ) & ret;
	ret = hash_context->update( this->hostname ) & ret;
	ret = hash_context->update( this->ip ) & ret;
	ret = hash_context->update( this->mac ) & ret;
	return ret;
 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

}; // namespace wosh
